package guestbook;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.http.*;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class GuestbookServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();

		System.out
				.println(req.getSession().getServletContext().getRealPath(""));
		if (user != null) {
			resp.setContentType("text/plain");
			resp.getWriter().println(
					"Hello, "
							+ user.getNickname()
							+ "\tpath:::"
							+ req.getSession().getServletContext().getRealPath(
									""));
			Properties props=System.getProperties(); // 获得系统属性集  
			String osName = props.getProperty("os.name"); // 操作系统名称  
			String osArch = props.getProperty("os.arch"); // 操作系统构架  
			String osVersion = props.getProperty("os.version"); // 操作系统版本 
			resp.getWriter().print("osName:" + osName + ",osArch" + osArch + ",osVersion" + osVersion);
		} else {
			resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
		}
	}
}
